<?php
/**
 * ============================================================================
 * @copyright China International Consulting. 中国国际咨询
 * @version:  v1.0
 * @website   http://www.chinacons.com
 * ---------------------------------------------
 * $Date: 2007.12.17
*/

  session_start();
  session_cache_limiter('private,must-revalide');
  include_once("./config.php");
  $tpl = new PhplibTpl($conf["admin_tpl_path"]);
  if (! empty($_GET['mode']) )
  {   
    include($conf["include_path"] . $_GET['mode'] . ".php");
  }
  $new_cate_id =$_POST['s_cate'];
  
    //分类列表文件
  include($conf["include_path"] . "list_cate.php");
  $tpl->set_file("main", "recycle.htm");
  $tpl->set_block("main", "PRO_LIST", "pro_list");

  $btn_all = $_REQUEST['btn_all'];

  if($btn_all)
  {
	  session_unregister('cat_id');
	  session_unregister('key');
	  $query = "SELECT * FROM $TBL_NEWS WHERE 1";
  }
  else
  {
	  $query = "SELECT * FROM $TBL_NEWS WHERE 1 ";
	 //用户按下了"查找"  
	  if(isset($_REQUEST["s_cate"]))  //要显示的分类
	  {
		  $_SESSION['cat_id']=$_REQUEST["s_cate"];
	  }
	  $cate_id=$_SESSION['cat_id'];
	  if ( !empty($cate_id))
	  {	  
		  $tmp_str = "";  //所有的子类
		  get_News_Sub($tmp_str, $cate_id);
		  $tmp_str = substr($tmp_str, 1, strlen($tmp_str));
		  if (! empty($tmp_str))
		  {
			$query .= " and `cate_id` in (" . $cate_id . "," . $tmp_str . ")";
		  } 
		  else
		  {
			$query .= " and `cate_id` in (" . $cate_id . ")";
		  }//End if
	  } //End if
	  //$search_key = work_str($_REQUEST["search_key"] );  //查找关键字
	  if(isset($_REQUEST["search_key"]))
	  {
		  $_SESSION['key']=$_REQUEST["search_key"];
	  }
	  $search_key= work_str($_SESSION['key']);
	  if (! empty($search_key))
	  {
		  $search_str = " and (`zh_headline` like '%" . $search_key . "%' or `zh_keywords` like '%" . $search_key . "%')";
	  } //End if 
  }
 
  $query .= " AND display=0 order by date_added desc";

  //实现分页
  include( $conf['base_path'] . "lib/make_pages.php");
  $cur_page = (int)$_GET["p"];   //获取当前页
  $url_param = preg_replace("/(p=[0-9]+)&/", "", $_SERVER['QUERY_STRING']);
  $pages = new Pager($query, $cur_page, 20, $url_param);
  $page_string = $pages -> getPageString();   
  $res = $pages -> getRsPerPage();
  while ($rows = mysql_fetch_array($res))
  {
    $news_id = $rows["id"];
	$query = "SELECT zh_cate_title,parent_id FROM $TBL_CATE WHERE cate_id=".$rows['cate_id'];
	$result = mysql_query($query) or die(mysql_error());
	$array = @mysql_fetch_array( $result );

	$query1 = "SELECT zh_cate_title FROM $TBL_CATE WHERE cate_id=".$array['parent_id'];
	$result1 = mysql_query($query1) or die(mysql_error());
	$array1 = @mysql_fetch_array( $result1 );

    $edit_url = "?mode=direct&id=" . $news_id;
    $del_url = "?mode=del_news&del_id=". $news_id;
	$pub_date = $rows["date_added"];      //发布日期
	$show_type=$array_show[$rows['sh_id']];
	$tpl -> set_var(array(
		               "CATE_TITLE" => $array['zh_cate_title'],
	                   "NEWS_ID" => $news_id,
                       "EDIT_URL" => $edit_url,
					   "DEL_URL" => $del_url,
					   "C_NAME" => $rows["zh_headline"],
		               "E_NAME" => $rows["en_headline"],
					   "PAR_TITLE" => $array1['zh_cate_title'],
					   "PUB_DATE" => date("y年n月j日",$pub_date),
		               "AUTHOR" => $rows['author'],
					   "cate_id" => $rows['cate_id'],
					   "SHOW_NAME"=> ($show_type!="")?"【".$show_type."】":"",
					   "puttip" => ($rows['puttip']==1)?"【置顶】":"",
	                ));
	$tpl -> parse("pro_list", "PRO_LIST", true);
  } //End while
  if (empty($page_string))
    $page_string = "此条件下暂时没有文章";
  $tpl -> set_var(array(
                        "SEARCH_KEY" => $search_key,
                        "SHOW_CATE" => $show_cate,
						"INIT_CATE" => $init_cate,
                        "PAGE_STRING" => $page_string
                      ));
  $tpl -> parse("Output", "main");
  $tpl -> p("Output");
?>